package com.t3go.t3_map.base;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.shareware.common.utils.LogExtKt;
import com.t3map.api.map.T3MapView;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;

public class CommonPlatformViewFactory extends PlatformViewFactory {
    private static final String CLASS_NAME = "CommonPlatformViewFactory";
    private final BinaryMessenger binaryMessenger;
    private View container;
    private int viewId;

    public CommonPlatformViewFactory(BinaryMessenger binaryMessenger) {
        super(StandardMessageCodec.INSTANCE);
        LogExtKt.log(CLASS_NAME, "HomeMapPlatformViewFactory");
        this.binaryMessenger = binaryMessenger;
    }

    @NonNull
    @Override
    public PlatformView create(Context context, int viewId, Object args) {
        this.viewId = viewId;
        LogExtKt.log(CLASS_NAME, "create PlatformView,viewId=" + viewId + ",args=" + args + ",container=" + container);
        return new PlatformView() {
            @Nullable
            @Override
            public View getView() {
                LogExtKt.log(CLASS_NAME, "getView PlatformView,viewId=" + viewId);
                return new T3MapView(context);
            }

            @Override
            public void dispose() {
                LogExtKt.log(CLASS_NAME, "dispose PlatformView,viewId=" + viewId);
            }
        };
    }

    public void setContainerView(View container) {
        this.container = container;
    }


    public View getContainerView() {
        return container;
    }

    public int getViewId() {
        return viewId;
    }
}
